package isssr.bean.test;

import isssr.bean.entity.GoalStatus;
import isssr.bean.entity.OrganizationalGoal;
import isssr.bean.entity.Role;
import isssr.bean.entity.User;
import isssr.bean.utility.EncryptionUtility;

import java.util.ArrayList;

import org.junit.Test;

public class StoragePopulator {

	@Test
	public  void populate()
	{
		int num_users = 10;
		
		ArrayList<Role> roles= new ArrayList<Role>();
		
		Role role;
		int num_roles = (int) (num_users *0.7);
		
		for(int i=0; i<num_roles; i++)
		{
			role = new Role();
			
			role.setTitle("Role_" + i);
			
			switch( (i % 3) )
			{
			case 0 : role.setLevel(20);
				break;
			case 1 : role.setLevel(10);
				break;
			case 2 : role.setLevel(30);
				break;
			default : role.setLevel(15);
				break;
			}
			
			role.setDescription("Default Description");
			roles.add(role);
			try
			{
				role.save();
			}
			catch(Exception ex) 
			{
				ex.printStackTrace();
			}
		}
		
		ArrayList<User> users = new ArrayList<User>();
		User user;
		
		for(int i=0; i< num_users; i++)
		{
			user = new User();
			user.setFirstName("Mario");
			user.setLastName("Mario");
			user.setEmail("bonnie@gmail.com");
			user.setUsername("username_" + i);
			user.setPassword(EncryptionUtility.getHexHashingString("pass"));
			
			role = roles.get((int) (i * num_roles / num_users));
			user.setRole(role);
			
			try
			{
				user.save();
			}
			catch(Exception ex) 
			{
				ex.printStackTrace();
			}
			
			users.add(user);
		}
		
		GoalStatus status = GoalStatus.DEFINITION;
		
		ArrayList<OrganizationalGoal> goals = new ArrayList<OrganizationalGoal>();
		OrganizationalGoal goal;
		
		int num_goals = (int) (num_users*0.3);
		for(int i=0; i< num_goals; i++)
		{
			goal = new OrganizationalGoal();
			
			goal.setTitle("Goal_" + i);
			goal.setDescription("GenericDescription");
			goal.setEnumStatus(GoalStatus.DEFINITION);
			
			
			user = users.get((int) (i * num_users / num_goals ) );
			
			goal.setGoalOwner(user);

			try
			{
				goal.save();
			}
			catch(Exception ex)
			{
				ex.printStackTrace();
			}
			goals.add(goal);
		}
	}
	
	
}
